﻿using RBAC.Domain;

namespace RBAC.Interstructrue.Base
{
    public interface IBaseRepository<T> where T : BaseEntity
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Create(T entity);
        /// <summary>
        /// 修改 + 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Update(T entity);
        /// <summary>
        /// 通过ID获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetModel(long id);
        /// <summary>
        /// 获取所有数据 (EF Core方式，暂时保留)
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetALL();
        /// <summary>
        /// 获取所有数据 (Dapper方式)
        /// </summary>
        /// <returns></returns>
        List<T> GetAll();
        /// <summary>
        /// 获取所有数据 (Dapper方式) - 带条件
        /// </summary>
        /// <param name="whereClause">WHERE条件</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        List<T> GetAll(string whereClause = "", object? parameters = null);
        /// <summary>
        /// 获取单个实体 (Dapper方式) - 带条件
        /// </summary>
        /// <param name="whereClause">WHERE条件</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        T? GetFirstOrDefault(string whereClause = "", object? parameters = null);
        /// <summary>
        /// 执行自定义SQL查询 (Dapper方式)
        /// </summary>
        /// <typeparam name="TResult">返回类型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        List<TResult> Query<TResult>(string sql, object? parameters = null);
        /// <summary>
        /// 执行自定义SQL查询返回单个结果 (Dapper方式)
        /// </summary>
        /// <typeparam name="TResult">返回类型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        TResult? QueryFirstOrDefault<TResult>(string sql, object? parameters = null);
        /// <summary>
        /// 分页查询 (Dapper方式)
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页数量</param>
        /// <param name="whereClause">WHERE条件</param>
        /// <param name="orderBy">排序</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        (List<T> Data, int TotalCount) GetPaged(int pageIndex, int pageSize, string whereClause = "", string orderBy = "", object? parameters = null);

        /// <summary>
        /// 批量插入实体 (Dapper方式)
        /// </summary>
        /// <param name="entities">实体列表</param>
        /// <returns>影响的行数</returns>
        int CreateBatch(List<T> entities);

        /// <summary>
        /// 执行自定义SQL (Dapper方式)
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数</param>
        /// <returns>影响的行数</returns>
        int Execute(string sql, object? parameters = null);

        /// <summary>
        /// 执行存储过程 (Dapper方式)
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <param name="parameters">参数</param>
        /// <returns>影响的行数</returns>
        int ExecuteStoredProcedure(string procedureName, object? parameters = null);
    }
}
